package com.scy.lock;

import jakarta.annotation.Resource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Component;

import java.util.concurrent.locks.Lock;

/**
 * @Author：sichenyong
 * @Email: sichenyongwork@163.com
 * @Package：com.scy.lock
 * @Project：Redis7NewDataStructure
 * @Date：2024/5/8 19:31
 * @description：
 */
@Component
public class DistributedLockFactory {
    @Resource
    private StringRedisTemplate stringRedisTemplate;

    private String lockName = "scyRedisLock";

    public Lock getDistributedLock(String lockType, String uuidValue) {
        if ("redis".equalsIgnoreCase(lockType)) {
            // redis 分布式锁
            return new RedisDistributedLock(stringRedisTemplate, lockName, uuidValue);
        }
        else {
            // 没有提供
            return null;
        }
    }
}
